package com.gem.springbootdemo.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

//MVC增强版这只
@Configuration   //代表为配置文件  application_web.xml的配置文件
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private UrlInterceptor urlInterceptor;
    //给静态资源放行


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(urlInterceptor).addPathPatterns("/**").
                excludePathPatterns("/static/**").
                excludePathPatterns("/css/**").
                excludePathPatterns("/js/**").
                excludePathPatterns("/images/**").
                excludePathPatterns("/img/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //静态资源放行 /static     放置静态资源
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

    }

    //将引导作用的control在这里和view进行配置
    //使用了springMVC的增强版,所有的静态资源前面必须添加static
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //toLogin  controller 跳转到 login.html
        // toRegister   register
        registry.addViewController("/toRegister").setViewName("/register");
//        引导页的注册

    }

}
